﻿using Leo.Awesome.DictionaryManagement.Domain;
using Leo.Awesome.DictionaryManagement.MongoDB;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.MongoDB;

namespace Leo.Awesome.DictionaryManagement.Repositories
{
    public class DictionaryItemRepository : BaseMongoDbAbpRepository<DictionaryManagementMongoDbContext, DictionaryItem, Guid>, IDictionaryItemRepository
    {
        public DictionaryItemRepository(IMongoDbContextProvider<DictionaryManagementMongoDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public async Task< List<DictionaryItem>> GetDictiionaryItemBySectionCode(string sectionCode)
        {
            var queryable = await GetMongoQueryableAsync();
            return await queryable
                .WhereIf<DictionaryItem, IMongoQueryable<DictionaryItem>>(
                !sectionCode.IsNullOrEmpty(),
                s => s.Code == sectionCode && s.IsEnabled ==true
                )
                .ToListAsync();
        }

        public async Task<List<DictionaryItem>> GetDictiionaryItem()
        {
            var queryable = await GetMongoQueryableAsync();
            return await queryable               
                .ToListAsync();
        }
    }
}
